package com.oros.db;
import com.vditl.core.*;
import java.io.Serializable;

public class AEUniqueIndexPool implements Serializable {
    /**
	 * 
	 */
	private static final long serialVersionUID = -7718552345149928172L;
	private UniVector pool;
    private int dim;
    private int[] cols;
    public AEUniqueIndexPool(int[] cols)
    {
    	pool=new UniVector();
    	this.cols = cols;
    	this.dim = cols.length;
    }
    public void clear()
    {
    	pool.clear();
    }
    public int size()
    {
    	return pool.size();
    }
    public AEUniqueIndexItem get(Object[] dat)
    {
    	if (dat==null || dat.length!=dim) return null;
        AEUniqueIndexItem a = new AEUniqueIndexItem(dat,null);
        int n=pool.indexOf(a);
    	if (n<0) return null;
    	return (AEUniqueIndexItem)pool.get(n);
    }
    public AEUniqueIndexItem get(AEUniqueIndexItem sample)
    {
    	int n=pool.indexOf(sample);
    	if (n<0) return null;
    	return (AEUniqueIndexItem)pool.get(n);
    }
    public AEUniqueIndexItem get(AERawItem item)
    {
        Object[] dat=new Object[dim];
        for(int i=0;i<dim;i++) dat[i]=item.getColumnValue(cols[i]);
        AEUniqueIndexItem sample = new AEUniqueIndexItem(dat,item);
    	int n=pool.indexOf(sample);
    	if (n<0) return null;
    	return (AEUniqueIndexItem)pool.get(n);
    }
     
    public boolean add(AERawItem item) 
    {
        Object[] dat=new Object[dim];
        for(int i=0;i<dim;i++) dat[i]=item.getColumnValue(cols[i]);
        AEUniqueIndexItem a = new AEUniqueIndexItem(dat,item);
        int n=pool.indexOf(a);
        if (n>=0) return false;
        pool.add(a);
        return true;
    }
    public String getItemUniqueInfo(AERawItem item)
    {
        Object[] dat=new Object[dim];
        for(int i=0;i<dim;i++) dat[i]=item.getColumnValue(cols[i]);
        AEUniqueIndexItem a = new AEUniqueIndexItem(dat,item);
        return a.toString();                       	
    }
}
